home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 75 / Mac Magazin CD 75.iso / macware / Red Bird's Quick Scripts / Lock Screen / Lock Screen 0.3 (Keychain).as next >
Encoding:
Text File  |  2000-07-28  |  5.5 KB  |  113 lines  |  [TEXT/ToyS]

  1. (*
  2. Lock Screen 0.3:  Keep folks from using your computer.  NOT SECURE!
  3. Copyright (C) 2000 Gordon Worley.
  4.  
  5. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version.
  6.  
  7. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  8.  
  9. For a copy of the GNU General Public License, visit <http://www.gnu.org/> or write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330, Boston, MA 02111-1307, USA.
  10.  
  11. To contact me, please visit my Web site at <http://www.rbisland.cx/> or e-mail me at <redbird@rbisland.cx>.
  12.  
  13. History:
  14.  
  15. 0.3 - Added a show_background function to counteract the effects of hide_background.  A few cravaets mentioned below.
  16. 0.2 - Added a hide_background function that hides all of the background processes, keeping prying eyes from prying.
  17. 0.1 - Added Keychain support.  Has some problems, though.  Check the documentation and comments for info.
  18. 0.0 - Initial release.
  19. *)
  20.  
  21. --I can't say this enough:  THIS SCRIPT IS NOT SECURE!!!!!!  It is very easy to subvert this system, but will keep casual onlookers from seeing anything.
  22. --Force quiting gets around this program.  Fortunately for you, most people don't know how to do it (command-option-esc).
  23.  
  24. on run
  25.     set the_response to display dialog "Lock Screen 0.3.  What do you want to do to your screen? " buttons {"Nothing", "Manual Lock", "Auto Lock"} default button 2
  26.     if the_response's button returned is "Manual Lock" then
  27.         my manual_lock()
  28.     else if the_response's button returned is "Auto Lock" then
  29.         my auto_lock()
  30.     else
  31.         return
  32.     end if
  33. end run
  34.  
  35. on manual_lock()
  36.     set the_password to display dialog "Enter password to use to lock this computer." default answer "" buttons {"Okay"} default button 1 with icon 1 --enter the password you want here.  remember:  NOT SECURE!!!!
  37.     set the_password to the_password's text returned --put the password in this variable
  38.     my hide_background()
  39.     set keep_locked to true
  40.     repeat while keep_locked is true --keep looping until corrent answer is entered
  41.         set entered_password to display dialog "Please enter password to access this computer." default answer "" buttons {"Okay"} default button 1 with icon 2
  42.         --I could really use some bullet text so that people can't see your password as you type it.  Any ideas?
  43.         if entered_password's text returned is the_password then --not secure either
  44.             set keep_locked to false
  45.         else
  46.             display dialog "Oops, that's not it.  You need to enter the correct password to access this computer." buttons {"All right..."} default button 1 with icon 0
  47.         end if
  48.     end repeat
  49.     my show_background()
  50. end manual_lock
  51.  
  52. on auto_lock()
  53.     my hide_background()
  54.     --this is experimental and has problems.  explained below
  55.     set keep_locked to true
  56.     repeat while keep_locked is true
  57.         set the_password_response to display dialog "Please enter password to access this computer." default answer "" buttons {"Okay"} default button 1 with icon 2
  58.         set the_password to the_password_response's text returned
  59.         tell application "Keychain Scripting"
  60.             try
  61.                 unlock with password the_password --if given the wrong password once, it will not work again, even given the correct password, until the correct password is manuly entered into Kyechain Access.  Don't know what causes this.  Any ideas?
  62.                 lock
  63.                 set keep_locked to false
  64.             on error
  65.                 display dialog "Oops, that's not it.  You need to enter the correct password to access this computer." buttons {"All right..."} default button 1 with icon 0
  66.             end try
  67.         end tell
  68.     end repeat
  69.     my show_background()
  70. end auto_lock
  71.  
  72. on hide_background()
  73.     --thanks to Apple for the code I used to make this (I just made a few modification to what was in one of the Speakable Items scripts).
  74.     tell application "Finder"
  75.         --every visible background process.  The Finder will never be in this list
  76.         set all_processes to (every process whose visible is true and frontmost is false)
  77.         if all_processes ≠ {} then
  78.             repeat with a_process in all_processes
  79.                 set the visible of a_process to false
  80.             end repeat
  81.         end if
  82.         --make the Finder invisible
  83.         if ((the frontmost of application "Finder" is false) and (the visible of application "Finder" is true)) then
  84.             set the visible of application "Finder" to false
  85.         end if
  86.     end tell
  87. end hide_background
  88.  
  89. on show_background()
  90.     (*
  91.     As with anything, this has a few problems:
  92.          - Application Switcher doesn't update when the processes are made visible (they look like they're hidden)
  93.          - I had to add a try structure because many processes not listed in the Application Switcher can't be made visible (but I guess they can be made invisible ;-))
  94.      Sorry, these are Apple's fault.  There are probably more, I just don't know about them yet.
  95.      *)
  96.     tell application "Finder"
  97.         --every hidden background process.  The Finder will never be in this list
  98.         set all_processes to (every process whose visible is false and frontmost is false)
  99.         if all_processes ≠ {} then
  100.             repeat with a_process in all_processes
  101.                 try
  102.                     set the visible of a_process to true
  103.                 on error
  104.                     --pass
  105.                 end try
  106.             end repeat
  107.         end if
  108.         --make the Finder visible
  109.         if ((the frontmost of application "Finder" is false) and (the visible of application "Finder" is false)) then
  110.             set the visible of application "Finder" to true
  111.         end if
  112.     end tell
  113. end show_background